package com.qishanor.framework.common.oss.config;

import com.qishanor.framework.common.oss.http.OssEndpoint;
import com.qishanor.framework.common.oss.service.FileTemplate;
import com.qishanor.framework.common.oss.service.LocalFileTemplate;
import com.qishanor.framework.common.oss.service.OssTemplate;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * aws 自动配置类
 *
 * @author zeus
 * @author 858695266
 */
@Configuration
@RequiredArgsConstructor
public class FileAutoConfiguration {

    private final FileProperties properties;

    @Bean
    @Primary
    @ConditionalOnMissingBean(OssTemplate.class)
    @ConditionalOnProperty(name = "file.oss.enable", havingValue = "true")
    public FileTemplate ossTemplate() {
        return new OssTemplate(properties);
    }

    @Bean
    @ConditionalOnMissingBean(LocalFileTemplate.class)
    @ConditionalOnProperty(name = "file.local.enable", havingValue = "true", matchIfMissing = true)
    public FileTemplate localFileTemplate() {
        return new LocalFileTemplate(properties);
    }


//    @Bean
//    @ConditionalOnProperty(name = "file.oss.enable", havingValue = "true")
//    public OssEndpoint ossEndpoint(OssTemplate template) {
//        return new OssEndpoint(template);
//    }

}
